﻿
using UnityEngine;
using UnityEngine.AI;

namespace UFrame
{
    /// <summary>
    /// Unity烘培寻路API
    /// </summary>
    public class NavTool
    {
        public static Vector3 GetRandomLocation()
        {
            NavMeshTriangulation navMeshData = NavMesh.CalculateTriangulation();

            int t = Random.Range(0, navMeshData.indices.Length - 3);

            Vector3 point = Vector3.Lerp(navMeshData.vertices[navMeshData.indices[t]], 
                navMeshData.vertices[navMeshData.indices[t + 1]], Random.value);
            
            point = Vector3.Lerp(point, navMeshData.vertices[navMeshData.indices[t + 2]], Random.value);

            return point;
        }
    }
}